﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WebServer.DBUtility;
using WebServer.Models;

namespace WebServer.DBAccess
{
    public class BourseDA
    {
        #region 交易所信息-总数/列表[字段少/可根据名称查询/字段多]/热门交易所/根据CenterID获取信息/修改/删除/交易所最大CenterID
        /// <summary>
        /// 交易所总数
        /// </summary>
        /// <param name="Simple"></param>
        /// <param name="IsOpen"></param>
        /// <returns></returns>
        public int BourseCounts(int IsOpen)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Bourse_CM]", IsOpen);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


       /// <summary>
       /// 获取交易所列表【字段少】
       /// </summary>
       /// <param name="Page"></param>
       /// <param name="PageSize"></param>
       /// <param name="isOpen"></param>
       /// <param name="OrderID">0-创建时,1-Name,2-Tel，3-Email，4-Address，5-Img</param>
       /// <param name="Desc"></param>
       /// <returns></returns>
        public List<BourseA> BourseListA(int Page, int PageSize, bool isOpen, int OrderID, bool Desc)
        {
            List<BourseA> request = new List<BourseA>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Bourse_QC]", new object[] { Page, PageSize, isOpen }))
                {

                    while (reader.Read())
                    {
                        BourseA entity = new BourseA();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Name = reader[2].ToString();
                        entity.MediumName = reader[3].ToString();
                        entity.Shortened = reader[4].ToString();
                        entity.Img = reader[9].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 获取交易所列表【可根据名称查询】
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>       
        /// <param name="isOpen"></param>
        /// <param name="Remak">查询条件【名称】</param>
        /// <param name="OrderID">0-创建时,1-Name,2-Tel，3-Email，4-Address，5-Img</param>
        /// <returns></returns>
        public List<BourseC> BourseListB(int Page, int PageSize, int isOpen, string Remak, int OrderID, bool Desc)
        {
            List<BourseC> request = new List<BourseC>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Bourse_QB]", new object[] { Page, PageSize, isOpen, Remak, OrderID, Desc }))
                {

                    while (reader.Read())
                    {
                        BourseC entity = new BourseC();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Name = reader[2].ToString();
                        entity.MediumName = reader[3].ToString();
                        entity.Shortened = reader[4].ToString();
                        entity.Tel = reader[5].ToString();
                        entity.Email = reader[6].ToString();
                        entity.Address = reader[7].ToString();
                        entity.Text = reader[8].ToString();
                        entity.Img = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            entity.CreateTime = reader[10].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.WebSite = reader[11].ToString();
                        entity.OpenWeb = reader[12].ToString();
                        entity.SoftUrl = reader[13].ToString();
                        entity.Poundage = reader[14].ToString();
                        entity.InOutGold = reader[15].ToString();
                        if (reader[16] != DBNull.Value)
                            entity.IsOpen = reader[16].ToBoolean();
                        else
                            entity.IsOpen = false;
                        if (reader[17] != DBNull.Value)
                            entity.UpdateTime = reader[17].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;
                        entity.OpenDays = reader[18].ToString();
                        entity.OpenHours = reader[19].ToString();
                        entity.OpenWebRole = reader[20].ToString();
                        entity.Bank = reader[21].ToString();
                        entity.Week = reader[22].ToString();
                        entity.QQ = reader[23].ToString();
                        entity.House = reader[24].ToString();
                        entity.Seniority = reader[25].ToString();
                        entity.Config = reader[26].ToString();
                        if (reader[27] != DBNull.Value)
                            entity.IsShow = reader[27].ToInt32();
                        else
                            entity.IsShow = 0;
                        entity.OpenAppRole = reader[28].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 获取交易所列表【字段多】
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>       
        /// <param name="isOpen"></param>
        /// <param name="OrderID">0-创建时,1-Name,2-Tel，3-Email，4-Address，5-Img</param>
        /// <returns></returns>
        public List<BourseC> BourseListC(int Page, int PageSize, int isOpen, int OrderID, bool Desc)
        {
            List<BourseC> request = new List<BourseC>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Bourse_QC]", new object[] { Page, PageSize, isOpen, OrderID, Desc }))
                {

                    while (reader.Read())
                    {
                        BourseC entity = new BourseC();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Name = reader[2].ToString();
                        entity.MediumName = reader[3].ToString();
                        entity.Shortened = reader[4].ToString();
                        entity.Tel = reader[5].ToString();
                        entity.Email = reader[6].ToString();
                        entity.Address = reader[7].ToString();
                        entity.Text = reader[8].ToString();
                        entity.Img = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            entity.CreateTime = reader[10].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.WebSite = reader[11].ToString();
                        entity.OpenWeb = reader[12].ToString();
                        entity.SoftUrl = reader[13].ToString();
                        entity.Poundage = reader[14].ToString();
                        entity.InOutGold = reader[15].ToString();
                        if (reader[16] != DBNull.Value)
                            entity.IsOpen = reader[16].ToBoolean();
                        else
                            entity.IsOpen = false;
                        if (reader[17] != DBNull.Value)
                            entity.UpdateTime = reader[17].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;
                        entity.OpenDays = reader[18].ToString();
                        entity.OpenHours = reader[19].ToString();
                        entity.OpenWebRole = reader[20].ToString();
                        entity.Bank = reader[21].ToString();
                        entity.Week = reader[22].ToString();
                        entity.QQ = reader[23].ToString();
                        entity.House = reader[24].ToString();
                        entity.Seniority = reader[25].ToString();
                        entity.Config = reader[26].ToString();
                        if (reader[27] != DBNull.Value)
                            entity.IsShow = reader[27].ToInt32();
                        else
                            entity.IsShow = 0;
                        entity.OpenAppRole = reader[28].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 热门交易所
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="Sort">默认根据回复，1-创建时间</param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public List<BourseA> BourseSort(int PageSize = 0, int PageIndex = 0, int Sort = 0, bool Desc = true)
        {
            List<BourseA> request = new List<BourseA>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_A_Bourse_Sort", new object[] { PageSize, PageIndex, Sort, Desc }))
                {
                    while (reader.Read())
                    {
                        BourseA entity = new BourseA();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Name = reader[2].ToString();
                        entity.Shortened = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.ReTotal = reader[4].ToInt32();
                        else
                            entity.ReTotal = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 查询指定交易所
        /// </summary>
        /// <param name="CenterID">CenterID</param>
        /// <returns></returns>
        public BourseC BourseByCenterID(int CenterID)
        {
            BourseC request = new BourseC();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Bourse_One]", new object[] { CenterID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.CenterID = reader[1].ToInt32();
                        else
                            request.CenterID = 0;
                        request.Name = reader[2].ToString();
                        request.MediumName = reader[3].ToString();
                        request.Shortened = reader[4].ToString();
                        request.Tel = reader[5].ToString();
                        request.Email = reader[6].ToString();
                        request.Address = reader[7].ToString();
                        request.Text = reader[8].ToString();
                        request.Img = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.UpdateTime = reader[11].ToDateTime();
                        else
                            request.UpdateTime = DateTime.Now;
                        request.WebSite = reader[12].ToString();
                        request.OpenWeb = reader[13].ToString();
                        request.OpenWebRole = reader[14].ToString();
                        request.OpenAppRole = reader[15].ToString();
                        request.SoftUrl = reader[16].ToString();
                        request.Poundage = reader[17].ToString();
                        request.InOutGold = reader[18].ToString();
                        if (reader[19] != DBNull.Value)
                            request.IsOpen = reader[19].ToBoolean();
                        else
                            request.IsOpen = false;
                        request.OpenDays = reader[20].ToString();
                        request.OpenHours = reader[21].ToString();
                        request.Bank = reader[22].ToString();
                        request.Week = reader[23].ToString();
                        request.QQ = reader[24].ToString();
                        request.House = reader[25].ToString();
                        request.Seniority = reader[26].ToString();
                        request.Config = reader[27].ToString();

                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 修改或者添加交易所
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int BourseSet(BourseC entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { entity.CenterID, entity.Name, entity.MediumName, entity.Shortened, entity.Tel, entity.Email, entity.Address, entity.Text, entity.Img, entity.WebSite, entity.OpenWeb, entity.OpenWebRole, entity.OpenAppRole, entity.SoftUrl, entity.Poundage, entity.InOutGold, entity.OpenDays, entity.OpenHours, entity.Bank, entity.Week, entity.QQ, entity.House, entity.Seniority, entity.Config };
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Bourse_Set]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }



        /// <summary>
        /// 删除交易所
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int BourseDel(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Bourse_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 交易所最大CenterID
        /// </summary>
        /// <returns></returns>
        public int getMaxCenterID()
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();

                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Bourse_MaxID]");
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion


        #region 藏品信息-总数/列表[可根据名称查询]/根据CenterID，Code获取信息/获取最近N天上线的/藏品介绍/根据交易所CenterID获取藏品库存/修改/删除
        /// <summary>
        /// 藏品总数
        /// </summary>
        /// <param name="Simple"></param>
        /// <param name="IsOpen"></param>
        /// <returns></returns>
        public int GoodsCount(int CenterID, string Code, string Key, int IsOpen)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Goods_CM]", new object[] { CenterID, Code, Key, IsOpen });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 获取藏品列表【根据名称查询】
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <param name="Simple"></param>
        /// <param name="Key"></param>
        /// <param name="IsOpen"></param>
        /// <param name="Order">默认-修改时间,1-CenterID,2-Shortened,3-Code,4-Fullname,5-OnLinePrice,6-OnLinePrice,7-Stock,8-Circulation,9-PublishTime</param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        /// <returns></returns>
        public List<Goods> GoodsListA(int Page, int PageSize, int CenterID, string Code, bool Simple, string Key, int IsOpen, int Order, bool Desc)
        {
            List<Goods> request = new List<Goods>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Goods_QA]", new object[] { Page, PageSize, CenterID, Code, Key, IsOpen, Order, Desc }))
                {

                    while (reader.Read())
                    {
                        Goods entity = new Goods();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Code = reader[3].ToString();
                        entity.Fullname = reader[4].ToString();

                        if (Simple == false)
                        {
                            entity.OnLinePrice = reader[5].ToString();

                            if (reader[6] != DBNull.Value)
                                entity.OnLineTime = reader[6].ToDateTime();
                            else
                                entity.OnLineTime = DateTime.Now;

                            if (reader[7] != DBNull.Value)
                                entity.Stock = reader[7].ToInt32();
                            else
                                entity.Stock = 0;

                            if (reader[8] != DBNull.Value)
                                entity.Circulation = reader[8].ToInt32();
                            else
                                entity.Circulation = 0;

                            if (reader[9] != DBNull.Value)
                                entity.PublishTime = reader[9].ToDateTime();
                            else
                                entity.PublishTime = DateTime.Now;

                            if (reader[10] != DBNull.Value)
                                entity.UpdataTime = reader[10].ToDateTime();
                            else
                                entity.UpdataTime = DateTime.Now;

                            entity.Cate = reader[11].ToString();

                            if (reader[12] != DBNull.Value)
                                entity.Money = reader[12].ToDecimal();
                            else
                                entity.Money = 0;

                            if (reader[13] != DBNull.Value)
                                entity.SingleMoney = reader[13].ToDecimal();
                            else
                                entity.SingleMoney = 0;

                            if (reader[14] != DBNull.Value)
                                entity.SinglePosition = reader[14].ToDecimal();
                            else
                                entity.SinglePosition = 0;
                            //此字段使用为当前藏品所在交易所的总数
                            if (reader[15] != DBNull.Value)
                                entity.Retotal = reader[15].ToInt32();
                            else
                                entity.Retotal = 0;
                        }
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 查询指定藏品
        /// </summary>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <returns></returns>s
        public Goods GoodsByCode(int CenterID, string Code)
        {
            Goods request = new Goods();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Goods_One]", new object[] { CenterID, Code }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.CenterID = reader[1].ToInt32();
                        else
                            request.CenterID = 0;
                        request.CenterName = reader[2].ToString();
                        request.Code = reader[3].ToString();
                        request.Fullname = reader[4].ToString();

                        request.OnLinePrice = reader[5].ToString();

                        if (reader[6] != DBNull.Value)
                            request.OnLineTime = reader[6].ToDateTime();
                        else
                            request.OnLineTime = DateTime.Now;

                        if (reader[7] != DBNull.Value)
                            request.Stock = reader[7].ToInt32();
                        else
                            request.Stock = 0;

                        if (reader[8] != DBNull.Value)
                            request.Circulation = reader[8].ToInt32();
                        else
                            request.Circulation = 0;

                        if (reader[9] != DBNull.Value)
                            request.PublishTime = reader[9].ToDateTime();
                        else
                            request.PublishTime = DateTime.Now;

                        if (reader[10] != DBNull.Value)
                            request.UpdataTime = reader[10].ToDateTime();
                        else
                            request.UpdataTime = DateTime.Now;

                        request.Cate = reader[11].ToString();

                        if (reader[12] != DBNull.Value)
                            request.Money = reader[12].ToDecimal();
                        else
                            request.Money = 0;

                        if (reader[13] != DBNull.Value)
                            request.SingleMoney = reader[13].ToDecimal();
                        else
                            request.SingleMoney = 0;

                        if (reader[14] != DBNull.Value)
                            request.SinglePosition = reader[14].ToDecimal();
                        else
                            request.SinglePosition = 0;

                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取最近N天上线的
        /// </summary>
        /// <param name="Times"></param>
        /// <returns></returns>
        public List<Goods> GoodsListed(DateTime Times)
        {
            List<Goods> request = new List<Goods>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Goods_Listed]", new object[] { Times }))
                {

                    while (reader.Read())
                    {
                        Goods entity = new Goods();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Code = reader[3].ToString();
                        entity.Fullname = reader[4].ToString();


                        entity.OnLinePrice = reader[5].ToString();

                        if (reader[6] != DBNull.Value)
                            entity.OnLineTime = reader[6].ToDateTime();
                        else
                            entity.OnLineTime = DateTime.Now;

                        if (reader[7] != DBNull.Value)
                            entity.Stock = reader[7].ToInt32();
                        else
                            entity.Stock = 0;

                        if (reader[8] != DBNull.Value)
                            entity.Circulation = reader[8].ToInt32();
                        else
                            entity.Circulation = 0;

                        if (reader[9] != DBNull.Value)
                            entity.PublishTime = reader[9].ToDateTime();
                        else
                            entity.PublishTime = DateTime.Now;

                        if (reader[10] != DBNull.Value)
                            entity.UpdataTime = reader[10].ToDateTime();
                        else
                            entity.UpdataTime = DateTime.Now;

                        entity.Cate = reader[11].ToString();

                        if (reader[12] != DBNull.Value)
                            entity.Money = reader[12].ToDecimal();
                        else
                            entity.Money = 0;

                        if (reader[13] != DBNull.Value)
                            entity.SingleMoney = reader[13].ToDecimal();
                        else
                            entity.SingleMoney = 0;

                        if (reader[14] != DBNull.Value)
                            entity.SinglePosition = reader[14].ToDecimal();
                        else
                            entity.SinglePosition = 0;

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 藏品介绍
        /// </summary>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public string GoodsIntroduce(int CenterID, string Code)
        {
            string request = string.Empty;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Goods_Details]", new object[] { CenterID, Code }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToString();
                        else
                            request = "";
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 根据交易所CenterID获取藏品库存
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <param name="Simple"></param>
        /// <param name="Key"></param>
        /// <param name="IsOpen"></param>
        /// <param name="Order">默认-修改时间,1-CenterID,2-Shortened,3-Code,4-Fullname,5-OnLinePrice,6-OnLinePrice,7-Stock,8-Circulation,9-PublishTime</param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public List<GoodsStock> GoodsStock(int Page, int PageSize, int CenterID, string Code,  string Key, int IsOpen, int Order, bool Desc)
        {
            List<GoodsStock> request = new List<GoodsStock>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_Goods_QA]", new object[] { Page, PageSize, CenterID, Code, Key, IsOpen, Order, Desc }))
                {
                    while (reader.Read())
                    {
                        GoodsStock entity = new GoodsStock();
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[3].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Stock = reader[7].ToInt32();
                        else
                            entity.Stock = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 修改或者添加藏品
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int GoodsSet(Goods entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { entity.ID, entity.CenterID, entity.Code, entity.Fullname, entity.OnLinePrice, entity.OnLineTime, entity.Stock, entity.Circulation, entity.PublishTime, entity.Cate, entity.Money, entity.SingleMoney, entity.SinglePosition };
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Goods_Set]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 删除藏品
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int GoodsDel(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_Goods_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region App首页显示交易所-App首页显示交易所列表/ 是否显示在APP首页
        /// <summary>
        /// App首页显示交易所列表
       /// </summary>
       /// <param name="Page"></param>
       /// <param name="PageSize"></param>
       /// <param name="isOpen"></param>
       /// <param name="Remak"></param>
       /// <param name="OrderID">0-创建时,1-Name,2-Tel，3-Email，4-Address，5-Img</param>
       /// <param name="Desc"></param>
       /// <param name="Simple"></param>
       /// <returns></returns>
        public List<BourseC> BourseAPPQ(int Page, int PageSize, int isOpen, string Remak, int OrderID, bool Desc, bool Simple)
        {
            List<BourseC> request = new List<BourseC>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_BourseAPP_QA]", new object[] { Page, PageSize, isOpen, Remak, OrderID, Desc, }))
                {

                    while (reader.Read())
                    {
                        BourseC entity = new BourseC();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Name = reader[2].ToString();
                        entity.MediumName = reader[3].ToString();
                        entity.Shortened = reader[4].ToString();
                        entity.Img = reader[9].ToString();
                        if (reader[19] != DBNull.Value)
                            entity.IsOpen = reader[19].ToBoolean();
                        else
                            entity.IsOpen = false;
                        if (Simple == false)
                        {
                            entity.Tel = reader[5].ToString();
                            entity.Email = reader[6].ToString();
                            entity.Address = reader[7].ToString();
                            entity.Text = reader[8].ToString();
                            if (reader[10] != DBNull.Value)
                                entity.CreateTime = reader[10].ToDateTime();
                            else
                                entity.CreateTime = DateTime.Now;
                            if (reader[11] != DBNull.Value)
                                entity.UpdateTime = reader[11].ToDateTime();
                            else
                                entity.UpdateTime = DateTime.Now;
                            entity.WebSite = reader[12].ToString();
                            entity.OpenWeb = reader[13].ToString();
                            entity.OpenWebRole = reader[14].ToString();
                            entity.OpenAppRole = reader[15].ToString();
                            entity.SoftUrl = reader[16].ToString();
                            entity.Poundage = reader[17].ToString();
                            entity.InOutGold = reader[18].ToString();                           
                            entity.OpenDays = reader[20].ToString();
                            entity.OpenHours = reader[21].ToString();                           
                            entity.Bank = reader[22].ToString();
                            entity.Week = reader[23].ToString();
                            entity.QQ = reader[24].ToString();
                            entity.House = reader[25].ToString();
                            entity.Seniority = reader[26].ToString();
                            entity.Config = reader[27].ToString();
                        }
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

      /// <summary>
        /// 是否显示在APP首页
      /// </summary>
      /// <param name="CenterID"></param>
      /// <param name="IsShow">true-显示，false-取消显示</param>
      /// <returns></returns>
        public int BourseAPP(int CenterID,bool IsShow)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_BourseAPP_Set]", new object[] { CenterID, IsShow });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion

        #region PC首页显示交易所-PC首页显示交易所/修改
        /// <summary>
        ///  PC首页显示交易所
        /// </summary>
        /// <returns></returns>
        public BoursePC BoursePCList()
        {
            BoursePC entity = new BoursePC();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_A_BoursePC_Q]", new object[] { }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.NewsBourseID = reader[1].ToString();
                        entity.HotBourseID = reader[2].ToString();
                        entity.BourseID = reader[3].ToString();
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entity;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Fn"></param>
        /// <param name="PCValue"></param>
        /// <returns></returns>
        public int BoursePCSet(int Fn, string PCValue)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { Fn, PCValue };
                object obj = sqlHelp.ExecuteSPScalar("[sp_A_BoursePC_Set]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        #endregion
    }
}
